package com.jackiechancinema.ssm.controller;

import com.jackiechancinema.ssm.bo.AdminBo;
import com.jackiechancinema.ssm.dto.AdminDto;
import com.jackiechancinema.ssm.entity.Admin;
import com.jackiechancinema.ssm.service.Impl.AdminServiceImpl;
import com.jackiechancinema.ssm.vo.PageVo;
import com.jackiechancinema.ssm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;


@RestController
@RequestMapping("/main")
public class AdminController {

    @Autowired
    private AdminServiceImpl adminService;
//    @GetMapping("/adminPage")
//    public PageVo<Admin> admin(int page,int limit){
//        return adminService.queryPage(page,limit);
//    }
    @GetMapping("/adminPage")
    public PageVo<Admin> admin(AdminBo bo){
    return adminService.queryPage(bo);

}
    @PostMapping("/save")
    public R save(AdminDto adminDto){
        return adminService.saveAdmin(adminDto);
    }
    @PostMapping("/update")
    public R update(Admin admin){
        return adminService.update(admin);
    }
    @PostMapping("/delete")
    public R delete(int id){
        return adminService.delete(id);
    }
    @PostMapping("/changepass")
    public R updatePassword(String oldpass, String newpass, HttpSession session){
        return adminService.updatePassWord(oldpass,newpass,session);
    }
    @PostMapping("/batchDel")
    public R batchDel(@RequestBody List<Admin> adminList){
        return adminService.batchDel(adminList);
    }
    @PostMapping("/batchadd")
    public R batch(MultipartFile file){
        return adminService.batchAdd(file);
    }
    //下载，导出excel表格
    @GetMapping("/download")
    public void download(AdminBo bo, HttpServletResponse response){
        adminService.exportExcel(bo,response);
    }
}
